﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_bid_project_product_bidTable : System.Web.UI.Page
{
    public string ProjectId;
    protected void Page_Load(object sender, EventArgs e)
    {
        string BidNum, strSql;
        ProjectId = SysFun.IsSQL(Request.QueryString["ProjectId"]);
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            if (!IsPostBack)
            {
                lstDY.Items.Add("全部");
                lstDY.Items.Add("已对应");
                lstDY.Items.Add("未对应");
            }
            if (ProjectId == null)
            {
                Response.Write("<script language=JavaScript>window.alert('没有找到相关的项目！！！！');</script>");

            }
            else
            {
                HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                if (Request.Form["SaveId"] == "保存编号")
                {
                    foreach (string strId in SysFun.ToTrim(Request.Form["hiddenId"]).Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        BidNum = SysFun.ToTrim(Request.Form["txt" + strId]);
                        if (BidNum != "")
                        {
                            Db db = new Db();
                            strSql = "update bid_project_product set BidNum='" + BidNum + "' WHERE Id=" + strId;
                            db.Command(strSql);
                            db.Close();

                            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "bid_project_product", strSql, "../Agency/bid_project_product_bidTable.aspx");

                        }
                    }
                }
                if (Request.Form["chk"] != null && Request.Form["delId"] == "删除")
                {
                    Db db1 = new Db();
                    strSql = "delete from  bid_project_product  WHERE Id in (" + Request.Form["chk"].ToString() + ")";
                    db1.Command(strSql);
                    db1.Close();
                    HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "删除", "bid_project_product", strSql, "../Agency/bid_project_product_bidTable.aspx");

                }
                labProjectId.Text = ProjectId;
                show();
            }
        }
    }

    public void show()
    {
        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();
        strHtml.Append("<table width='98%' cellSpacing='1' cellPadding='2'  align='center' class='list' ><tr><th>品目号</th><th>招标通用名</th><th>招标剂型</th><th>招标规格</th><th>通用名</th><th>剂 型</th><th>规 格</th><th>转换系数</th><th>单 位</th><th>招标编码</th><th>修改</th><th>删除</th></tr>");
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "bid_project_product_bidTable";                                               //要查询的表明
        dbPage.Key = "Id";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "Id,ProjectId,ProductId,ProductName,Medicinemodel,Outlookc,Unit,BidTableId,BidTableName,BidTableType,BidTableOutlookc,ProductCode,BidNum,xishu";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 20;                                                    //没有显示记录条数   
        dbPage.OrderBy = "ProductCode,ProductName,Medicinemodel,Outlookc";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        int i = 0;
        while (dr.Read())
        {
            i += 1;
            if (i % 2 == 0)
            {
                strHtml.Append("<tr class='table_td'>");
            }
            else
            {
                strHtml.Append("<tr class='table_td2'>");
            }
            strHtml.Append("<td ><input type='hidden' name='hiddenId' value='" + dr["Id"].ToString() + "'/>" + dr["ProductCode"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["BidTableName"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["BidTableType"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["BidTableOutlookc"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["ProductName"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Medicinemodel"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Outlookc"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["xishu"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Unit"].ToString() + "</td>");
            strHtml.Append("<td><input type=text style='width=70' value='" + dr["BidNum"].ToString() + "' name ='txt" + dr["Id"].ToString() + "' onblur=\"javascript:if(!/^[A-Za-z0-9]+$/.test(this.value)){alert('品目号只能由数字和英文字母组成！');return false;}\" /></td>");
            strHtml.Append(" <td><a target='_blank' href='bid_project_product_bidTable_Add.aspx?ProjectId=" + ProjectId + "&Id=" + dr["Id"].ToString() + "&ProductId=" + dr["ProductId"].ToString() + "'>修改</a></td>");
            strHtml.Append("<td><input name='chk' type='checkbox' value='" + dr["Id"].ToString() + "'></td>");
            strHtml.Append("</tr>");

        }
        strHtml.Append("</table>");
        Label9.Text = strHtml.ToString();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

    }

    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp, ProductName, Medicinemodel, Outlookc, BidTableName, BidTableType, BidTableOutlookc, ProductCode, BidNum, DY;
        ProjectId = labProjectId.Text.ToString().Trim();
        ProductName = txtProductName.Text.ToString().Trim();
        Medicinemodel = txtMedicinemodel.Text.ToString().Trim();
        Outlookc = txtOutlookc.Text.ToString().Trim();
        BidTableName = txtBidTableName.Text.ToString().Trim();
        BidTableOutlookc = txtBidTableOutlookc.Text.ToString().Trim();
        BidTableType = txtBidTableType.Text.ToString().Trim();
        ProductCode = txtProductCode.Text.ToString().Trim();
        BidNum = txtBidNum.Text.ToString().Trim();
        strtemp = " ProjectId=" + ProjectId + " and";
        DY = lstDY.SelectedValue;
        switch (DY)
        {
            case "全部":
                break;
            case "已对应":
                strtemp += " BidTableName is not null and";
                break;
            case "未对应":
                strtemp += " BidTableName is null and";
                break;
        }
        if (ProductName != "")
        {
            strtemp = strtemp + " (ProductName like '%" + ProductName + "%' or " + " SpellingCode like '%" + ProductName + "%') and";
        }
        if (Medicinemodel != "")
        {
            strtemp = strtemp + " Medicinemodel like '%" + Medicinemodel + "%' and";
        }
        if (Outlookc != "")
        {
            strtemp = strtemp + " Outlookc like '%" + Outlookc + "%' and";
        }
        if (BidTableName != "")
        {
            strtemp = strtemp + " BidTableName like '%" + BidTableName + "%' and";
        }
        if (BidTableType != "")
        {
            strtemp = strtemp + " BidTableType like '%" + BidTableType + "%' and";
        }
        if (BidTableOutlookc != "")
        {
            strtemp = strtemp + " BidTableOutlookc like '%" + BidTableOutlookc + "%' and";
        }
        if (ProductCode != "")
        {
            strtemp = strtemp + " ProductCode like '%" + ProductCode + "%' and";
        }
        if (BidNum != "")
        {
            strtemp = strtemp + " BidNum like '%" + BidNum + "%' and";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;

    }


}
